DEV-900 Write Verisense RWC as base-station local civil time - #65
Merged
Conversation
The documented time-sync contract is that the device RWC holds the base station's LOCAL time (unix + local tz offset), which the downstream file parser depends on for midnight/midday CSV splits (pinned GMT+0 calendar) and 'Local =' header times. Adds utcToLocalCivilMillis()/localCivilUnixSecondsNow() helpers and VerisenseClient.writeTimeLocalNow(), documents the domain on writeTimeUnixSeconds, and switches formatVerisenseUnixAndHuman to the Date UTC accessors so a civil-domain value renders verbatim instead of having the browser offset applied a second time. New tests in tests/verisense/civil-time.test.ts; full suite 241 green. Version 0.1.7 -> 0.1.8. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR aligns Verisense real-world clock (RWC) time-sync behavior with the documented contract that the device clock stores the base station’s local civil time (Unix time with local timezone offset baked in), ensuring downstream CSV splitting/labeling logic operates correctly.
Changes:
- Added local-civil time helpers (
utcToLocalCivilMillis,localCivilUnixSecondsNow) and exported them from the SDK entrypoint. - Added
VerisenseBleDevice.writeTimeLocalNow()and clarified the domain expectations onwriteTimeUnixSeconds(). - Updated
formatVerisenseUnixAndHuman()to render via Date UTC accessors to avoid double-applying timezone offsets; added targeted tests and bumped version to 0.1.8.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/verisense/civil-time.test.ts | Adds coverage for offset-at-instant behavior (DST), wall-clock round-trip, and civil-domain rendering. |
| src/index.ts | Exposes the new civil-time helpers via the public SDK exports. |
| src/devices/verisense/VerisenseClient.ts | Adds writeTimeLocalNow() and documents correct RWC domain usage for time sync. |
| src/devices/verisense/protocolUtils.ts | Implements civil-time conversion helpers and switches human formatting to UTC accessors. |
| package.json | Bumps package version to 0.1.8. |
| package-lock.json | Updates lockfile version fields to 0.1.8. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The offset-application assertion compared the millisecond delta against -getTimezoneOffset()*60000, which computes to -0 on a UTC-timezone runner; vitest's toBe uses Object.is, where +0 !== -0, so CI (UTC) failed while local (BST, offset 60) passed. Compare absolute timestamps instead. Verified under TZ=UTC, TZ=Asia/Kuala_Lumpur and host BST; full suite 241 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DEV-900
Problem
The documented Verisense time-sync contract is that the device RWC holds the base station's local time (
VERISENSE_COMMUNICATION_PROTOCOL.md: "Synchronises the sensor's real-world clock with the Base Station's local time"). The downstream file parser depends on that domain: midnight/midday CSV splits are evaluated on the raw RWC value in a pinned GMT+0 calendar, and CSV columns are labelledUnix_ms_plus_local_time_zone_offset. The SDK previously had no local-civil helper, so consumers (web console) wrote plain UTC — proven by DEV-793's B9 midnight recording, which never split because device time ran 1 h behind civil time.Changes
utcToLocalCivilMillis()/localCivilUnixSecondsNow()inprotocolUtils.ts— the RWC domain conversion (offset evaluated at the instant converted, so DST rules apply correctly).VerisenseClient.writeTimeLocalNow()— one-call correct time sync; returns the seconds written.writeTimeUnixSeconds()pointing callers at the new method.formatVerisenseUnixAndHuman()now renders via the Date UTC accessors: a civil-domain value displays verbatim (the browser offset must not be applied a second time).Tests
New
tests/verisense/civil-time.test.ts(offset application incl. DST-instant evaluation, wall-clock round-trip, verbatim rendering, existing guards). Full suite: 241 tests green. Version 0.1.7 → 0.1.8.Consumer PR: verisense-device-console (same branch name).
🤖 Generated with Claude Code